﻿$(document).ready(function () {
	//Sample usage
	var isloggined = getCook('isloggined');
	$("#request-box").hide();	
    if(isloggined == 'true'){
    	$("#request-box").show();
    }
    //Hide error icon message default
    $(".span-error-ico").parent().hide();
});


function getCook(cookiename) {
	// Get name followed by anything except a semicolon
	var cookiestring=RegExp(""+cookiename+"[^;]+").exec(document.cookie);
	// Return everything after the equal sign
	return unescape(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./,"") : "");
}

/* Validation Utilities */

// Check value is null or empty
function isNullOrEmpty(value) {
    if (value == null)
        return true;
    else if (value == "")
        return true;
    else if ($.trim(value).length === 0)
        return true;
    else
        return false;
}
// Check value is integer number
function isIntegerNumber(value) {
    var pattern = new RegExp("^((\d+)|([+|-]\d+))$");
    return pattern.test(value);
}
// Check value is a number
function isNumberCharacters(value) {
    var pattern = new RegExp("^[0-9]+$");
    return pattern.test(value);
}

// Check phone number
function isPhoneNumber(value) {
    var pattern = new RegExp("^([0-9]{9})|([0-9]{10})|([0-9]{11})|([0-9]{12})|([0-9]{13})|(\([0-9]{3}\)\s+[0-9]{3}\-[0-9]{4})$");
    return pattern.test(value);
}
// Check constraint for XSS characters
function isInvalidXSSCharacters(value) {
    if (value != null || value.length > 0) {
        var pattern = XSS_CHARACTER_CHECK;
        for (var i = 0; i < pattern.length; i++) {
            if (value.indexOf(pattern[i]) > -1) {
                return true;
            }
        }
    }
    return false;
}
// Check minimum length
function isLessThanMiniumLength(value, minimumLength) {
    if ($.trim(value).length < minimumLength)
        return true;
    return false;
}
// Check max length
function isGreaterThanMaximumLength(value, maximumLength) {
    if ($.trim(value).length > maximumLength)
        return true;
    return false;
}
// Check the length of value on range
function isOnRange(value, minimumLength, maximumLength) {
    if ($.trim(value).length >= minimumLength
			&& $.trim(value).length <= maximumLength)
        return true;
    return false;
}
//Check identity number
function isIdentityNumber(value) {
    var pattern = new RegExp("^[0-9]{9,10}$");
    return pattern.test(value);
}
//Check email
function isEmail(value) {
    var pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return pattern.test(value);
}

//Display message on message container
function displayValidationMessage(messageType, messageText) {
    if (messageType == "error") {
        $("#messageContent").attr("class", "wrap-message-container error");
        $("#messageContent").html('<span class="ico"></span>' + messageText);
        $("#messageContent").parent().show();
    } else if (messageType == "success") {
        $("#messageContent").attr("class", "wrap-message-container success");
        $("#messageContent").html('<span class="ico"></span>' + messageText);
        $("#messageContent").parent().show();
    } else if (messageType == "info") {
        $("#messageContent").attr("class", "wrap-message-container info");
        $("#messageContent").html('<span class="ico"></span>' + messageText);
        $("#messageContent").parent().show();
    }
}

function hideValidationMessage() {
    $("#messageContent").removeAttr("class");
    $("#messageContent").html("");
    $("#messageContent").parent().hide();
}
